package com.wanlian.jpush.push.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.wanlian.util.StringUtil;

import java.util.ArrayList;
import java.util.List;


@JsonInclude(Include.NON_NULL)
public class PushSendVo implements ICheckable {

    /**
     * 平台
     */
    private Object platform;
    /**
     * 推送目标
     */
    private Object audience;
    /**
     * 通知
     */
    private Notification notification;
    private Message message;
    @JsonProperty(value = "sms_message")
    private Message smsMessage;
    @JsonProperty(value = "options")
    private Options options;
    private String cid;

    public PushSendVo() {
        platform = "all";
        audience = "all";
        // todo:默认为开发环境
        this.options = new Options(false);
    }

    public void selPlatFormAll() {
        platform = "all";
    }

    public void selAudienceAll() {
        audience = "all";
    }

    public void selPlatForm(boolean bandroid, boolean bios) {
        List<String> plist = new ArrayList<String>();
        if (bandroid) {
            plist.add("android");
        }
        if (bios) {
            plist.add("ios");
        }
        platform = plist;
    }

    public void setAudience(List<String> tags) {
        Audience maudience = new Audience();
        maudience.setTag(tags);
        this.audience = maudience;
    }

    public void setAudienceAlias(List<String> alias) {
        Audience maudience = new Audience();
        maudience.setAlias(alias);
        this.audience = maudience;
    }

    @Override
    public boolean checkIsAble() {
        if (platform != null) {
            if (platform instanceof String) {
                String mplatform = platform.toString();
                if (!StringUtil.hasValue(mplatform)) {
                    return false;
                }
            }
            if (audience instanceof String) {
                String maudience = audience.toString();
                if (!StringUtil.hasValue(maudience)) {
                    return false;
                }
            }
            if (notification == null) {
                if (message == null) {
                    return false;
                } else {
                    if (!message.checkIsAble()) {
                        return false;
                    } else {
                        return true;
                    }
                }
            } else {
                return notification.checkIsAble();
            }
        } else {
            return false;
        }
    }

    public Object getPlatform() {
        return platform;
    }

    public void setPlatform(Object platform) {
        this.platform = platform;
    }

    public Object getAudience() {
        return audience;
    }

    public Notification getNotification() {
        return notification;
    }

    public void setNotification(Notification notification) {
        this.notification = notification;
    }

    public Message getMessage() {
        return message;
    }

    public void setMessage(Message message) {
        this.message = message;
    }

    public Message getSmsMessage() {
        return smsMessage;
    }

    public void setSmsMessage(Message smsMessage) {
        this.smsMessage = smsMessage;
    }

    public Options getOptions() {
        return options;
    }

    public void setOptions(Options options) {
        this.options = options;
    }

    public String getCid() {
        return cid;
    }

    public void setCid(String cid) {
        this.cid = cid;
    }

}
